require.config({
    paths: {
        'jquery': ['http://cdn.bootcss.com/jquery/2.2.4/jquery.min', '/js/lib/jquery.min'],
        'doT': '/js/lib/doT.min',
        'bootstrap': '/js/lib/bootstrap.min',
        'datetimepicker': '/js/lib/bootstrap-datetimepicker.min',
        'select2': '/js/lib/select2.min'
    },
    shim: {
        'bootstrap': ['jquery']
    }
});

require(['jquery', 'doT', 'common', 'bootstrap'], function($, doT, common) {
    $(function() {
        $(function() {
            $('#goods_pic').on('change', function() {
                var reader = new FileReader();
                reader.onload = function(e) {
                    $('#preview').attr('src', e.target.result);
                    if (/image/.test($('#goods_pic')[0].files[0].type)) {
                        $('#preview').css('display', 'block');
                        $('#preview').show();
                    } else {
                        $('#errorMessage').show();
                    }
                };
                reader.readAsDataURL($('#goods_pic')[0].files[0]);
            });

        });

        var t;

        function addGoods() {
            var name = $('#goods_name').val();
            var info = $('#goods_info').val();
            var price = $('#goods_price').val();
            $('#addGoodsError').text('');
            if (!$('#goods_pic')[0].files[0]) {
                $('#addGoodsError').text('请选择商品图片');
            }
            if (!price) {
                $('#addGoodsError').text('请填写商品价格');
            }
            if (!info) {
                $('#addGoodsError').text('请填写商品简介');
            }
            if (!name) {
                $('#addGoodsError').text('请填写商品名称');
            }
            clearTimeout(t);
            if ($('#addGoodsError').text()) {
                $('#addGoodsError').parent().slideDown();
                t = setTimeout(function() {
                    $('#addGoodsError').parent().slideUp();
                }, 5000);
            }
            // $('#addGoodsMessageModal').modal('show');
        }

    });
});
